'''
coding:utf-8
@software:PyCharm
@time:16:21
@Author:hoo
'''
import time
import random
import datetime

import yaml

from commons.yaml_util import get_object_path


class demo:
    # 获取随机数
    def get_randon_number(self, min, max):
        return random.randint(int(min), int(max))

    # 获取8位随机数
    def get_random_number(self):
        random_number = str(random.randint(0, 100000000))
        return random_number

    # 获取当前日期
    def get_current_date(self):
        now = datetime.datetime.now()
        return now.strftime("%Y%m%d")

    def get_current_data2(self):
        now = datetime.datetime.now()
        return now.strftime("%Y-%m-%d")

    # 获取当前时间
    def get_current_time(self):
        now = datetime.datetime.now()
        return now.strftime("%H%M%S")

    # 获取当前时间（包括年月日）
    def get_time(self):
        now = self.get_current_date() + self.get_current_time()
        return now

    # 获取当前毫秒级时间戳
    def get_timestmap(self):
        t = time.time()
        timestmap = round(t * 1000)
        return timestmap

    # 支付订单编号
    def orderId(self):
        id = 'YC' + str(self.get_timestmap()) + str(self.get_random_number())
        return id

    # 读取extract.yaml文件
    def read_extract_yaml(self, key):
        with open(get_object_path() + "/extract.yaml", 'r', encoding='utf-8') as f:
            value = yaml.load(stream=f, Loader=yaml.FullLoader)
            return value[key]


if __name__ == '__main__':
    # print(demo().read_extract_yaml('access_token'))
    print(demo().orderId())
    print(demo().get_current_data2())
